package com.factory.dao;

import com.factory.entity.Department;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface DepartmentDao {

    // 插入部门
    @Insert("INSERT INTO department(dept_name, manager, location) " +
            "VALUES(#{deptName}, #{manager}, #{location})")
    @Options(useGeneratedKeys = true, keyProperty = "deptId")
    int insertDepartment(Department department);

    // 根据ID删除部门
    @Delete("DELETE FROM department WHERE dept_id = #{deptId}")
    int deleteDepartment(Integer deptId);

    // 更新部门信息
    @Update("UPDATE department SET dept_name=#{deptName}, manager=#{manager}, " +
            "location=#{location} WHERE dept_id=#{deptId}")
    int updateDepartment(Department department);

    // 根据ID查询部门
    @Select("SELECT * FROM department WHERE dept_id = #{deptId}")
    Department selectDepartmentById(Integer deptId);

    // 查询所有部门
    @Select("SELECT * FROM department")
    List<Department> selectAllDepartments();

    // 根据部门名称查询
    @Select("SELECT * FROM department WHERE dept_name LIKE CONCAT('%', #{deptName}, '%')")
    List<Department> selectDepartmentsByName(String deptName);

    // 查询部门及其所有员工（一对多查询）- 在XML中实现
    Department selectDepartmentWithEmployees(Integer deptId);

    // 查询所有部门及其员工数量 - 在XML中实现
    List<Department> selectAllDepartmentsWithEmployeeCount();
}